package com.weijianhuawen.wjblog.admin.controller;

import com.weijianhuawen.wjblog.admin.mode.vo.comment.DeleteCommentReqVo;
import com.weijianhuawen.wjblog.admin.mode.vo.comment.ExamineCommentReqVo;
import com.weijianhuawen.wjblog.admin.mode.vo.comment.FindCommentPageListReqVo;
import com.weijianhuawen.wjblog.admin.mode.vo.comment.PublishCommentReqVo;
import com.weijianhuawen.wjblog.admin.service.AdminCommentService;
import com.weijianhuawen.wjblog.common.aspect.ApiOperationLog;
import com.weijianhuawen.wjblog.common.utils.PageResponse;
import com.weijianhuawen.wjblog.common.utils.Response;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @version: java version 8
 * @Author: weijianhuawen
 * @description:
 * @date: 2024-12-21 23:10
 */

@RequestMapping("/admin/comment")
@Api(tags = "Admin 评论模块")
@RestController
public class AdminCommentController {
    @Autowired
    private AdminCommentService adminCommentService;

    // 发布评论
    @PostMapping("/publish")
    @ApiOperation(value = "发布评论")
    @ApiOperationLog(description = "登录用户发布评论")
    public Response publishUserComment(@RequestBody @Validated PublishCommentReqVo vo) {
        return adminCommentService.publishComment(vo);
    }
    // 分页获取评论列表
    @PostMapping("/page/list")
    @ApiOperation(value = "后台获取评论分页列表")
    @ApiOperationLog(description = "获取评论分页列表，用与评论管理")
    public PageResponse findCommentPageList(@RequestBody @Validated FindCommentPageListReqVo vo) {
        return adminCommentService.findCommentPageList(vo);
    }

    // 删除评论
    @PostMapping("/delete")
    @ApiOperation(value = "删除评论")
    @ApiOperationLog(description = "根据id删除评论")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response deleteComment(@RequestBody @Validated DeleteCommentReqVo vo) {
        return adminCommentService.deleteComment(vo);
    }

    // 审核评论
    @PostMapping("/examine")
    @ApiOperation(value = "审核评论")
    @ApiOperationLog(description = "审核评论")
    @PreAuthorize("hasRole('ROLE_ADMIN')")
    public Response examineComment(@RequestBody @Validated ExamineCommentReqVo vo) {
        return adminCommentService.examineComment(vo);
    }
}
